<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="box"></div>
    <script>
        var date = new Date();
        box.innerHTML = date;
        setInterval(function(){
            var date = new Date();
            box.innerHTML = dates(date);
        },1000)

         //实现时间的格式化
        function dates() {
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();

            var hours = date.getHours();
            var hours = hours >= 10 ? hours : '0' + hours;

            var min = date.getMinutes();
            var min = min >= 10 ? min : '0' + min;

            var seconds = date.getSeconds();
            var seconds = seconds >= 10 ? seconds : '0' + seconds;

            var week = date.getDay();
            var arr =['星期天','星期一','星期二','星期三','星期四','星期五','星期六'];
            return year + '/' + month + '/' + day + ' '+ hours + ':'+ min +':' + seconds +' ' + arr[week] ;
        }
        var res = dates();
        console.log(res);
        
    </script>
</body>
</html>